package com.chanyachting.emall.action.newsactivity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.domain.Newsactivity;
import com.chanyachting.emall.domain.ServiceOptionType;
import com.chanyachting.emall.service.MemberService;
import com.chanyachting.emall.serviceImpl.MemberorderservicesBO;
import com.chanyachting.emall.util.DateUtil;
import com.chanyachting.emall.util.RequestUtil;

public class ReleaseAction extends Action {

	//上架新闻活动。
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		
		
//		NewsActivityForm naForm=(NewsActivityForm)form;
//		
//		NewsActivityService naservice=new NewsActivityServiceImpl();
//		
//		Newsactivity na=new Newsactivity();
//		
//		na.setId(naForm.getId());
//		
//		naservice.release(na);
		
		RequestUtil ru=new RequestUtil(request);
		
		int id=Integer.parseInt(ru.getParameter("id", "0"));
		
		Newsactivity na=new Newsactivity(id);
		
		if(na!=null){
			
			//检查会员是否购买/开启“新闻活动上架服务”
			Member member=(Member)ru.getSessionObject(MemberService.MEMBER_IN_SESSION, new Member());
			
			String optionType=ServiceOptionType.News_Shelves;
			
			boolean temp=MemberorderservicesBO.checkMmemberServiceByMemberAndOPType(member, optionType);
			
			if(temp){
				
				na.setStatus("01");
				
				if(na.getReleaseDate()==null)na.setReleaseDate(DateUtil.getDate());
				
				na.update();
				
				ru.setSuccessMsg();
				
			}else{
				
				ru.setMsg("上架失败！请购买/开启新闻活动上架服务。");
			}
				
		}
		
		return mapping.findForward("noReleasenewsactivityList");
	}
	
	

}
